package com.technology.education.data.model

import com.technology.education.data.AppData
import com.technology.education.ext.formatTime
import com.technology.education.ext.formatTimeMin
import com.technology.education.utils.DateUtils

/**
 *@author:create by BZY
 *Date: 2022/3/17 16
 * 辅导订单详情
 */

/**
 *@param answer    笔记内容	string
 *@param answerImages    笔记图片	array	string
 *@param commentContent    评价内容	string
 *@param commentResult    评价结果 1非常满意 0不太满意	string
 *@param commentTags    评价标签	array	string
 *@param duration    总时长	integer(int32)
 *@param endTime    结束时间	string(date-time)
 *@param id    订单号	string
 *@param placeTime    下单时间	string(date-time)
 *@param question    问题描述	string
 *@param questionImages    问题图片数组	array	string
 *@param remainDuration    剩余时间 毫秒	integer(int64)
 *@param startTime    开始时间
 *@param teacherAbandon    老师放弃订单 1是 0否	string
 *@param videoUrl 辅导视频连接
 *@param takeTime    接单时间	string(date-time)
 *@param teachOrderState    状态 1派单中 2抢单中 3已接单 4辅导中 5待评价 6审核中 7审核未通过 8已完成 9已取消
 */
data class TeacherOrderDetailModel(
    val answer: String?,
    val answerImages: List<String>?,
    val commentContent: String?,
    val commentResult: String,
    val commentTags: List<String>?,
    val duration: Int,
    val endTime: String?,
    val id: String,
    val placeTime: String,
    val question: String?,
    val questionImages: List<String>?,
    var remainDuration: Int,
    val startTime: String?,
    val student: Student,
    val takeTime: String?,
    var teachOrderState: String,
    val teacher: TeacherInfoModel?,
    val teacherAbandon: String?,
    var videoUrl: String?,
    var appointMe: String?
) {

    /**
     * 是否满意
     */
    val isSatisfied: Boolean get() = commentResult == "1"

    /**
     * 教师端展示的订单状态说明
     */
    val teacherStatusInfo: String
        get() = when (teachOrderState) {
            "1" -> if (appointMe == "1") if (remainDuration > 0) "学生指定订单,请及时接单" else "您未及时接单,其他老师可以进行抢单" else "学生指定订单,仅限指定老师接单"
            "2" -> "订单可抢单"
            "3" -> if (AppData.MEMBER_TYPE == "0") "等待老师发起视频辅导" else if (remainDuration > 0) "成功接单,请及时向学生发起视频辅导" else "长时间未发起视频,订单已取消"
            "4" -> "辅导中"
            "5" -> "待评价"
            "6" -> "审核中"
            "7" -> "审核未通过"
            "8" -> "辅导完成"
            "9" -> "订单已取消"
            else -> ""
        }

    /**
     * 只有派单,并且指定教师是自己才会展示接单按钮
     * 未指定,订单状态未待结单和已接单
     */
    val showTakeButton: Boolean get() = (teachOrderState == "1" && appointMe == "1") || teachOrderState == "2" || teachOrderState == "3" || teachOrderState == "4"

    val timeDiff: Int
        get() = ((System.currentTimeMillis() - DateUtils.stringToLong(
            placeTime,
            "yyyy-MM-dd HH:mm:ss"
        )) / 1000).toInt()

    val durationStr: String get() = formatTimeMin(duration)

    /**
     * 指定老师,当前老师的状态
     * 如果等待时间为结束显示待接单,结束显示老师未接单
     */
    val appointTeacherStatus: String
        get() = when (teachOrderState) {
            "1" -> if (remainDuration > 0) "待接单" else "老师未接单"
            "3" -> if (remainDuration > 0) "" else "老师长时间未回应"
            "4" -> "辅导中"
            else -> "辅导已结束"
        }
}

data class Student(
    val avatar: String,
    val id: String,
    val name: String
)
